package com.gdty.fprapp.activity;


import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;

import com.IDWORLD.Interface;
import com.gdty.fprapp.R;
import com.hc.pda.HcPowerCtrl;

import java.io.File;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;

public class TestActivity extends Activity {
    private static final int REQUEST_CODE = 1024;
    Context context;
    private static final String TAG = TestActivity.class.getSimpleName();
    private static final String BASE_PATH = Environment.getExternalStorageDirectory().getPath();
    private Switch mtoumingSwitch;
    private Switch mblakredSwitch;

    private Button mConnBtn;
    private Button mDisConnBtn;
    private Button mCancelBtn;
    private Button mPressBtn;
    private Button mGetSnBtn;
    private Button mGetfingerlist;
    private Button mEmqtyBtn;
    private Button mGetInfoBtn;
    private Button mEnrollBtn;
    private Button mVerifyBtn;

    private ImageView mImageView;
    private TextView mHintTv;
    private Context mContext;

    private Spinner spinner;
    private Spinner spinner_baud;
    private List<String> data_list;
    private ArrayAdapter<String> arr_adapter;

    /////////////////
    private Interface zaclient;
    private int usbdevice = 0;
    int DEV_ADDR = 0xffffffff;
    int fpno = 0;
    boolean iscancle = false;
    boolean isshowbmp =false;
    int timeskipok = 0;
    int timeskiperror = 0;
    //////////
    String[] permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE};
    List<String> mPermissionList = new ArrayList<>();

    private static final int PERMISSION_REQUEST = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(0x80000000, 0x80000000);
//        setContentView(R.layout.activity_main_horizontal);


        if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setContentView(R.layout.activity_main_horizontal);

        } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            setContentView(R.layout.activity_main);

        }

        mContext = this;
        mtoumingSwitch = findViewById(R.id.toumingSwitch);
        mblakredSwitch = findViewById(R.id.blakredSwitch);
        mConnBtn = findViewById(R.id.connBtn);
        mDisConnBtn = findViewById(R.id.disconnBtn);
        mCancelBtn = findViewById(R.id.cancelBtn);
        mGetInfoBtn = findViewById(R.id.getInfoBtn);
        mPressBtn = findViewById(R.id.pressBtn);
        mGetSnBtn = findViewById(R.id.getSnBtn);
        mGetfingerlist = findViewById(R.id.getfingerlist);
        mEmqtyBtn = findViewById(R.id.getemqtyBtn);

        mEnrollBtn = findViewById(R.id.enrollBtn);
        mVerifyBtn = findViewById(R.id.verifyBtn);
        mImageView = findViewById(R.id.imgV);
        mHintTv = findViewById(R.id.hintTv);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            checkPermission();
        }
        InitDeviceList();
        zaclient = new Interface(this);
        btnOnClick();

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 是否触发按键为back键
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            iscancle=false;
            onBackPressed();
            return true;
        }else if(keyCode == KeyEvent.KEYCODE_MENU) {
            iscancle=false;
            super.openOptionsMenu(); // 调用这个，就可以弹出菜单
            return true;
        }
        else {// 如果不是back键正常响应
            return super.onKeyDown(keyCode, event);
        }
    }

    @Override
    protected void onUserLeaveHint() {
        iscancle=false;
        super.onUserLeaveHint();
    }
//
//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_MENU) {
//            iscancle=false;
//            super.openOptionsMenu(); // 调用这个，就可以弹出菜单
//        }
//        return true; // 最后，一定要做完以后返回 true，或者在弹出菜单后返回true，其他键返回super，让其他键默认
//    }

    @Override
    protected void onStop(){
        iscancle=false;
        CloseDev();
        super.onStop();
        System.out.println("后台APP运行");
    }
    @Override
    protected void onStart(){
        OpenDev();
        super.onStart();
        System.out.println("启动APP运行");
    }



    @RequiresApi(api = Build.VERSION_CODES.M)
    private void checkPermission() {
        mPermissionList.clear();
        //判断哪些权限未授予
        for (int i = 0; i < permissions.length; i++) {
            if (TestActivity.this.checkSelfPermission( permissions[i]) != PackageManager.PERMISSION_GRANTED) {
                mPermissionList.add(permissions[i]);
            }
        }
        /**
         * 判断是否为空
         */
        if (mPermissionList.isEmpty()) {//未授予的权限为空，表示都授予了
        } else {//请求权限方法
            String[] permissions = mPermissionList.toArray(new String[mPermissionList.size()]);//将List转为数组
            TestActivity.this.requestPermissions(  permissions, PERMISSION_REQUEST);
        }
    }

//    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        switch (requestCode) {
//            case PERMISSION_REQUEST:
//                break;
//            default:
//                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//                break;
//        }
//    }



    private void InitDeviceList()
    {
        spinner = (Spinner) findViewById(R.id.spinner);
        //数据
        data_list = new ArrayList<String>();
        data_list.add("USB");

        //适配器
        arr_adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data_list);
        //设置样式
        arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //加载适配器
        spinner.setAdapter(arr_adapter);

        spinner_baud = (Spinner) findViewById(R.id.spinner_baud);
        data_list = new ArrayList<String>();
        data_list.add(" ");
        //适配器
        arr_adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data_list);
        //设置样式
        arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //加载适配器
        spinner_baud.setAdapter(arr_adapter);


    }

    ////////////////
    // 心跳任务/
    ////////////////

    private void btnOnClick() {
        mConnBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                HcPowerCtrl ctrl = new HcPowerCtrl();
                ctrl.fingerPower(1);
                Sleep(1000);
                connBtnClick();//打开设备
            }
        });
        mDisConnBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                HcPowerCtrl ctrl = new HcPowerCtrl();
                ctrl.fingerPower(0);
                Sleep(1000);
                disconnBtnClick();//关闭设备
            }
        });
        mCancelBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                cancelBtnClick();//取消操作
            }
        });
        mGetInfoBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                getDevInfo();//获取参数信息
            }
        });
        mPressBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                pressBtnClick();//获取图像
            }
        });
        mGetSnBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                getSnBtnClick();//获取UUID
            }
        });
        mGetfingerlist.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                getfingerlistClick();//获取指纹列表
            }
        });
        mEmqtyBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EmqtyBtnClick();//清空指纹
            }
        });
        mEnrollBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                EnrollBtnClick();//注册指纹
            }
        });
        mVerifyBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                VerifyBtnClick();//搜索指纹
            }
        });

    }

    public static final int msgshow = 101;
    public static final int bmpshow = 102;
    public static final int alertshow = 103;
    public static final int enbtn = 104;
    public static final int disbtn = 105;

    private final Handler m_fEvent = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String temp  = null;
            switch (msg.what) {
                case msgshow:
                    mHintTv.setText(msg.obj.toString());
                    break;
                case bmpshow:
                    ShowFingerBitmap((byte[])(msg.obj),256,(int)(msg.arg1)/256);
                    break;
                case alertshow:
                    alert(msg.obj.toString());
                    break;
                case enbtn:

                    mHintTv.setText(msg.obj.toString());
                    break;
            }
        }
    };

    void alert(String str)
    {
        new AlertDialog.Builder(mContext)
                .setTitle("小小提示" )
                .setMessage(str )
                .setPositiveButton("确定" , null )
                .show();
    }
    void showToast( String text) {
        Toast mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
        mToast.show();
    }
    private void Sleep(int times)
    {
        try {
            Thread.sleep(times);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    protected void connBtnClick() {
//        writefile("/sdcard/Android/fps.bmp","1122343423423");
        Runnable r = new Runnable() {
            public void run() {
                Sleep(200);

                OpenDev();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void disconnBtnClick() {
        Runnable r = new Runnable() {
            public void run() {
                CloseDev();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void cancelBtnClick() {
        Runnable r = new Runnable() {
            public void run() {
                Cancel();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void getDevInfo() {
        Runnable r = new Runnable() {
            public void run() {
                getFingerInfo();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void pressBtnClick() {

        if(iscancle)
        {
            m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,"请先取消"));
            return;
        }
        iscancle = true;
        Runnable r = new Runnable() {
            public void run() {
                GetImage();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void getSnBtnClick() {
        Runnable r = new Runnable() {
            public void run() {
                GetFingerSn();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void getfingerlistClick() {
        Runnable r = new Runnable() {
            public void run() {
                GetFingerList();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void EmqtyBtnClick() {
        Runnable r = new Runnable() {
            public void run() {
                EmqtyFinger();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void EnrollBtnClick() {

        if(iscancle)
        {
            m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,"请先取消"));
            return;
        }
        iscancle = true;
        Runnable r = new Runnable() {
            public void run() {
                Enrollfinger();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }
    protected void VerifyBtnClick() {

        if(iscancle)
        {
            m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,"请先取消"));
            return;
        }
        iscancle = true;
        Runnable r = new Runnable() {
            public void run() {
                Searchfinger();
            }
        };
        Thread s = new Thread(r);
        s.start();
    }

    //打开设备
    private void OpenDev() {
        String dev = (String) spinner.getSelectedItem();
        String baund = (String) spinner_baud.getSelectedItem();
        if(dev.equals("USB")) {
            isshowbmp = true;
            usbdevice = zaclient.F_OpenDevice();
            if (usbdevice != 0)
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, "打开USB成功  " ));
            else
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, "打开USB失败  " ));
        }

    }
    private  void CloseDev(){
        int status = zaclient.F_CloseDevice(usbdevice);
        if(status == 1)
            m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,"关闭成功 status = "+status));
        else
            m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,"关闭失败 status = "+status));
        iscancle = false;
    }
    private void Cancel(){
        iscancle = false;
    }
    private void getFingerInfo()
    {
        byte[] pVersion = new byte[512];
        String msg;
        String ret  = zaclient.F_GetVersion();
        msg = "读取版本 ret = "+ret+"\r\n";
        m_fEvent.sendMessage(m_fEvent.obtainMessage(alertshow,0, 0,msg));
    }

    public static String toHexString(byte[] bytes) {
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        // 使用String的format方法进行转换
        for (byte b : bytes) {
            sb.append(String.format("%02x", new Integer(b & 0xff)));
        }

        return sb.toString();
    }

    private void GetFingerSn()
    {
        int ret =0;
        String msg;
        byte[] uuid = new byte[4];
        msg = "UUID:" ;
        m_fEvent.sendMessage(m_fEvent.obtainMessage(alertshow,0, 0,msg));
    }

    private void GetFingerList()
    {
        int len =0;
        String msg;
        int[] pParTable = new int[1024];
        len = 0;
        msg = "FingerDB:";
        for(int i =0;i<zaclient.getSize();i++) {
            msg += "" +i + ",";
        }
        m_fEvent.sendMessage(m_fEvent.obtainMessage(alertshow,0, 0,msg));
    }
    private void EmqtyFinger()
    {
        int ret =0;
        String msg;
        int[] pParTable = new int[1024];
        ret = 0;
        msg = "清空指纹 ret ="+ret ;
        zaclient.deletetable();
        m_fEvent.sendMessage(m_fEvent.obtainMessage(alertshow,0, 0,msg));

    }


    private void ShowFingerBitmap(byte[] image, int width, int height) {
        if (width==0) return;
        if (height==0) return;
        int[] RGBbits = new int[width * height];
        mImageView.invalidate();


        for (int i = 0; i < width * height; i++ ) {
            int v;
            int red=0;
            if (image != null) v = image[i] & 0xff;
            else v= 0;
            if (mblakredSwitch.isChecked()) {
                red = 255;
            }
            else
                red = v;
            if (mtoumingSwitch.isChecked()) {
                if(v<200)
                    RGBbits[i] = Color.argb(255,red, v, v);
                else
                    RGBbits[i] = Color.argb(0,red, v, v);
            }
            else
                RGBbits[i] = Color.argb(255,red, v, v);

        }
        Bitmap bmp = Bitmap.createBitmap(RGBbits, width, height, Bitmap.Config.ARGB_8888);
        mImageView.setImageBitmap(bmp);
    }
    public void writefile(String strFilePath,String strcontent) {
        // 每次写入时，都换行写
        String strContent = strcontent;// + "\n";
        try {
            File file = new File(strFilePath);
            if (!file.exists()) {
                Log.d("TestFile", "Create the file:" + strFilePath);
                file.createNewFile();
            }
            RandomAccessFile raf = new RandomAccessFile(file, "rw");
            raf.seek(file.length());
            raf.write(strContent.getBytes("utf-8"));
            raf.close();
        } catch (Exception e) {
            Log.e("TestFile", "Error on write File.");
        }
    }


    private void GetImage()
    {
        int ret =0;
        String msg="";
        byte[] Image = new byte[256*360];
        int [] len = new int[1];
        int timecount = 0;
        while(iscancle) {
            ret = zaclient.F_GetImage(usbdevice, Image);
            if (ret == 1) {
                msg = "获取图像成功 " + ret + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
            }
            else if (ret == (-100))
            {
                msg = "请先打开设备 " + ret + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                break;
            }
            else if (ret == (-101))
            {
                msg = "设备忙碌中 "  + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                Sleep(10);
                continue;
            }
            else{
                timecount++;
                msg = "连续获取指纹图像中\r\n请按“取消”停止当前操作\r\n获取图像中 time="+timecount+"\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
            }
            Sleep(100);
        }
        msg += "操作已取消";
        m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
        iscancle = false;
    }

    private void Enrollfinger()
    {
        int ret =0;
        String msg="";
        byte[] Image = new byte[256*360];
        byte[] itemplate = new byte[512];
        int [] len = new int[1];
        int timecount = 0;
        int bufferid = 0;
        while(iscancle) {


            ret = zaclient.F_GetImage(usbdevice,Image);
            if(ret == 1){
                msg = "获取图像成功\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow,256*360, 0,Image));
                ret = zaclient.F_CreateTemplate(usbdevice,Image,itemplate);
                if(ret != 0)
                {
                    msg += "生成特征成功\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                    if(zaclient.getSize()>=40){
                        msg += "注册失败，id列表已达上限\r\n";
                    }else {
                        zaclient.insert(itemplate);
                        msg += "注册成功,id:"+(zaclient.getSize()-1)+"\r\n";}

                }
                else if (ret == (-100))
                {
                    msg = "请先打开设备 " + ret + "\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                    break;
                }
                else if (ret == (-101))
                {
                    msg = "设备忙碌中 "  + "\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                    Sleep(10);
                    continue;
                }
                else
                {
                    msg += "生成特征失败\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                    Sleep(500);
                    continue;
                }
                break;
            }
            else if (ret == (-100))
            {
                msg = "请先打开设备 " + ret + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                break;
            }
            else if (ret == (-101))
            {
                msg = "设备忙碌中 "  + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                Sleep(10);
                continue;
            }
            else{
                timecount++;
                msg = "注册指纹中\r\n请按“取消”停止当前操作\r\n获取图像中 time="+timecount+"\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
            }
        }
        msg += "操作已结束";
        m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
        iscancle = false;
    }

    private void Searchfinger()
    {
        int ret =0;
        String msg="";
        byte[] Image = new byte[256*360];
        byte[] itemplate1 = new byte[512];
        byte[] itemplate2 = new byte[512];
        int [] len = new int[1];
        int[] iMbAddress = new int[1];
        int[]  iscore = new int[1];
        int timecount = 0;
        while(iscancle) {
            ret = zaclient.F_GetImage(usbdevice,Image);
            if(ret == 1){
                msg = "获取图像成功\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow,256*360, 0,Image));
                ret = zaclient.F_CreateTemplate(usbdevice,Image,itemplate1);
                if(ret > 20)
                {
                    msg += "生成特征成功 \r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                    ArrayList<byte[]> list=new ArrayList<>();
                    list=zaclient.searchtable();
                    int i=0;
                    for(i=0;i<list.size();i++){
                        ret =  zaclient.F_CompareTemplates(usbdevice,itemplate1,list.get(i));
                        if(ret>60){
                            msg += "查询成功，id为："+i +" \r\n";
                            break;
                        }
                    }
                    if(i == list.size())
                    {
                        msg += "查询失败,id总数:"+list.size()+" \r\n";
                    }
                    break;
                }
                else if (ret == (-100))
                {
                    msg = "请先打开设备 " + ret + "\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                    return ;
                }
                else if (ret == (-101))
                {
                    msg = "设备忙碌中 "  + "\r\n";
                    m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                    Sleep(10);
                    continue;
                }
                else{
                    msg = "生成特征失败 "  + "\r\n";
                }
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
                Sleep(500);
            }
            else if (ret == (-100))
            {
                msg = "请先打开设备 " + ret + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                return ;
            }
            else if (ret == (-101))
            {
                msg = "设备忙碌中 "  + "\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow, 0, 0, msg));
                m_fEvent.sendMessage(m_fEvent.obtainMessage(bmpshow, 256 * 360, 0, Image));
                Sleep(10);
                continue;
            }
            else{
                timecount++;
                msg = "搜索指纹中\r\n请按“取消”停止当前操作\r\n获取图像中 time="+timecount+"\r\n";
                m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
            }
        }
        msg += "操作已结束";
        m_fEvent.sendMessage(m_fEvent.obtainMessage(msgshow,0, 0,msg));
        iscancle = false;
    }



}


